package com.taoxi.member.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.taoxi.common.annotation.Log;
import com.taoxi.common.core.controller.BaseController;
import com.taoxi.common.core.domain.AjaxResult;
import com.taoxi.common.enums.BusinessType;
import com.taoxi.member.domain.Cart;
import com.taoxi.member.service.ICartService;
import com.taoxi.common.utils.poi.ExcelUtil;
import com.taoxi.common.core.page.TableDataInfo;

/**
 * 购物车管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-14
 */
@Api(tags = "购物车管理Controller")
@RestController
@RequestMapping("/member/cart")
public class CartController extends BaseController
{
    @Autowired
    private ICartService cartService;

    /**
     * 查询购物车管理列表
     */
    @ApiOperation("查询购物车管理列表")
    @PreAuthorize("@ss.hasPermi('member:cart:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cart cart)
    {
        startPage();
        List<Cart> list = cartService.selectCartList(cart);
        return getDataTable(list);
    }

    /**
     * 导出购物车管理列表
     */
    @ApiOperation("导出购物车管理列表")
    @PreAuthorize("@ss.hasPermi('member:cart:export')")
    @Log(title = "购物车管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cart cart)
    {
        List<Cart> list = cartService.selectCartList(cart);
        ExcelUtil<Cart> util = new ExcelUtil<Cart>(Cart.class);
        util.exportExcel(response, list, "购物车管理数据");
    }

    /**
     * 获取购物车管理详细信息
     */
    @ApiOperation("获取购物车管理详细信息")
    @PreAuthorize("@ss.hasPermi('member:cart:query')")
    @GetMapping(value = "/{cartId}")
    public AjaxResult getInfo(@PathVariable("cartId") Long cartId)
    {
        return success(cartService.selectCartByCartId(cartId));
    }

    /**
     * 新增购物车管理
     */
    @ApiOperation("新增购物车管理")
    @PreAuthorize("@ss.hasPermi('member:cart:add')")
    @Log(title = "购物车管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cart cart)
    {
        return toAjax(cartService.insertCart(cart));
    }

    /**
     * 修改购物车管理
     */
    @ApiOperation("修改购物车管理")
    @PreAuthorize("@ss.hasPermi('member:cart:edit')")
    @Log(title = "购物车管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cart cart)
    {
        return toAjax(cartService.updateCart(cart));
    }

    /**
     * 删除购物车管理
     */
    @ApiOperation("删除购物车管理")
    @PreAuthorize("@ss.hasPermi('member:cart:remove')")
    @Log(title = "购物车管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cartIds}")
    public AjaxResult remove(@PathVariable Long[] cartIds)
    {
        return toAjax(cartService.deleteCartByCartIds(cartIds));
    }
}
